package com.bango.nokia.java;

import java.util.Date;
import java.util.Vector;

import org.json.me.JSONArray;
import org.json.me.JSONObject;

class BangoEvent
{
	private int _profileId;
	private int _eventId;
	private String _eventName;
	private String _eventValue;
	private String _eventDetail;
	private String _errorId;
	private long _eventTime;
	private long _eventLocalTime;
	private int _connectionType;
	private String _operatorConnectionType;
	private int _errorLevel;
	private Vector _eventParameters;
	private boolean _eventPosted = false;

	void ProfileId(int profileId)
	{
		_profileId = profileId;
	}

	int ProfileId()
	{
		return _profileId;
	}

	void EventId(int eventId)
	{
		_eventId = eventId;
	}

	int EventId()
	{
		return _eventId;
	}

	void EventName(String eventName)
	{
		_eventName = eventName;
	}

	String EventName()
	{
		return _eventName;
	}

	void EventDetail(String eventDetail)
	{
		_eventDetail = eventDetail;
	}

	String EventDetail()
	{
		return _eventDetail;
	}

	void EventValue(String eventValue)
	{
		_eventValue = eventValue;
	}

	String EventValue()
	{
		return _eventValue;
	}

	void ErrorId(String errorId)
	{
		_errorId = errorId;
	}

	String ErrorId()
	{
		return _errorId;
	}

	void EventTime(Date eventTime)
	{
		_eventTime = eventTime.getTime();
	}

	Date EventTime()
	{
		return new Date(_eventTime);
	}

	void EventLocalTime(Date eventLocalTime)
	{
		_eventLocalTime = eventLocalTime.getTime();
	}

	Date EventLocalTime()
	{
		return new Date(_eventLocalTime);
	}

	void ConnectionType(int connectionType)
	{
		_connectionType = connectionType;
	}

	int ConnectionType()
	{
		return _connectionType;
	}

	void OperatorConnectionType(String operatorConnectionType)
	{
		_operatorConnectionType = operatorConnectionType;
	}

	String OperatorConnectionType()
	{
		return _operatorConnectionType;
	}

	void ErrorLevel(int errorLevel)
	{
		_errorLevel = errorLevel;
	}

	int ErrorLevel()
	{
		return _errorLevel;
	}

	void EventParameters(Vector eventParameters)
	{
		_eventParameters = eventParameters;
	}

	Vector EventParameters()
	{
		return _eventParameters;
	}

	void EventPosted(boolean eventPosted)
	{
		_eventPosted = eventPosted;
	}

	boolean EventPosted()
	{
		return _eventPosted;
	}

	BangoEvent()
	{

	}

	BangoEvent(int eventId, int connectionType, String operatorConnectionType, int errorLevel, String eventName, String eventValue, String eventDetail, String errorId, Date eventTime, Date eventLocalTime, Vector eventParameters)
	{
		_eventId = eventId;
		_connectionType = connectionType;
		_operatorConnectionType = operatorConnectionType;
		_eventName = eventName;
		_eventValue = eventValue;
		_eventDetail = eventDetail;
		_eventTime = eventTime.getTime();
		_eventLocalTime = eventLocalTime.getTime();
		_errorId = errorId;
		_errorLevel = errorLevel;
		_eventParameters = eventParameters;
		_eventPosted = false;
	}

	JSONObject GetEventDetails()
	{
		JSONObject returnValue = new JSONObject();
		JSONArray eventParameters = new JSONArray();
		JSONObject eventParameterObject;
		BangoNameValuePair eventParameter;
		try
		{
			returnValue.put(BangoFieldNames.POST_EVENTID, _eventId);
			returnValue.put(BangoFieldNames.POST_EVENTTIME, BangoStatic.GetDateString(new Date(_eventTime)));
			returnValue.put(BangoFieldNames.POST_EVENTLOCALTIME, BangoStatic.GetDateString(new Date(_eventLocalTime)));
			returnValue.put(BangoFieldNames.POST_CONNECTIONTYPE, BangoStatic.ConnectionType(_connectionType));
			returnValue.put(BangoFieldNames.POST_OPERATORCONNECTIONTYPE, _operatorConnectionType);
			returnValue.put(BangoFieldNames.POST_EVENTNAME, _eventName);
			returnValue.put(BangoFieldNames.POST_EVENTDETAIL, _eventDetail);
			returnValue.put(BangoFieldNames.POST_EVENTVALUE, _eventValue);
			returnValue.put(BangoFieldNames.POST_ERRORID, _errorId);
			returnValue.put(BangoFieldNames.POST_ERRORLEVEL, _errorLevel);
			if (_eventParameters != null)
			{
				for (int eventParameterCounter = 0; eventParameterCounter < _eventParameters.size(); eventParameterCounter++)
				{
					eventParameter = (BangoNameValuePair) _eventParameters.elementAt(eventParameterCounter);
					eventParameterObject = new JSONObject();
					eventParameterObject.put(BangoFieldNames.POST_PARAMETERNAME, eventParameter.Name());
					eventParameterObject.put(BangoFieldNames.POST_PARAMETERVALUE, eventParameter.Value());
					eventParameters.put(eventParameterObject);
				}
			}
			returnValue.put(BangoFieldNames.POST_EVENTPARAMETERS, eventParameters);

		}
		catch (Exception ex)
		{
		}

		return returnValue;
	}
}
